
#ifndef _MEMBER_BCAMERA_H_
#define _MEMBER_BCAMERA_H_

#include <BMap>
#include <BPlane>
#include <BImage>
#include <BNode>
#include <BLight>
#include <BScene>
#include <BCamera>
#include <BHandler>
#include <BOpenGL>
#include "IFrustum.h"

#include "member_BScene.h"

#define camera_member(camera)		((member_BCamera*)((BCamera*)camera)->_ptr)

namespace BWE
{
	struct ShapeInfo
	{
		BBox		box;
		BNodeHolder		node;
		BShapeHolder		shape;
	};
	typedef BArray<ShapeInfo>		ShapeInfoArray;
	typedef BMap<BReal, ShapeInfo> ShapeInfoQueue;

	class member_BCamera
	{
	public:
		member_BCamera(BCamera* camera);
		~member_BCamera();

		void adjust();

		void freshFrustum();

		void prepare();
		void prepare(SceneOctTreeItem& item);
		void prepare(BGroup* group);
		void prepareShapes(BSet<BNodeHolder>& nodes, BSet<BShapeHolder>& shapes);

		void frame(BScene* scene, BHandler* handler = 0);
		void renderHandler(BHandler* handler, BRender& render);

		BCamera*			boss;
		bool				ortho;
		BVector				center;
		BVector				direct;
		BVector				up;
		BReal				fovy;
		BReal				aspect;
		BReal				near;
		BReal				far;
		BReal				lensWidth;
		BReal				lensHeight;
		BSize				pixelSize;
		Policy				pixelSizePolicy;
		BColor				color;
		bool				culling;

		bool				refresh;
		bool				dirty;
		bool				fbo_resized;
		GLuint				fbo;
		GLuint				rbo_depth;
		GLuint				tbo;

		BScene*				scene;
		IFrustum			frustum;
		SceneOctTreeItemArray	sceneItems;
		BArray<BLight*>		lights;
		ShapeInfoArray		shapeArray;
		ShapeInfoQueue		transShapeQueue;

	};
}

#endif
